#coding:utf-8

import tensorflow as tf
with tf.Session() as sess:
    with tf.variable_scope('foo',initializer=tf.constant_initializer(4)):
        v=tf.get_variable('v',[1])
        tf.initialize_all_variables().run()
        assert v.eval()==4#被作用于初始化
        w=tf.get_variable('w',[1],initializer=tf.constant_initializer(0.5))
        tf.initialize_all_variables().run()
        assert w.eval()==0.5
        print('foo\t',v.name)
        with tf.variable_scope('bar'):
            tf.get_variable('v',[1])
            tf.initialize_all_variables().run()
            assert v.eval()==4
            print('bar\t',v.name)
        with tf.variable_scope('baz',initializer=tf.constant_initializer(1)):
            v=tf.get_variable('v',[1])
            tf.initialize_all_variables().run()
            print('baz\t',v.name)
            print('baz\t',v.eval())